import 'package:demo202112/utils/common_appbar.dart';
import 'package:flutter/material.dart';
/**
 * @Author wywinstonwy
 * @Date 2021/12/30 10:23 下午
 * @Description:
 */


class WyReorderableListView extends StatefulWidget {
  const WyReorderableListView({Key? key}) : super(key: key);

  @override
  _WyReorderableListViewState createState() => _WyReorderableListViewState();
}

class _WyReorderableListViewState extends State<WyReorderableListView> {
  List<String> items = List.generate(400, (int i) => '$i');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar('ReorderableListView'),
      body: _buildView1(),
    );
  }
  _buildView1(){
    return ReorderableListView(
        header: Text(
          '一枚有态度的程序员',
          style: TextStyle(color: Colors.red,fontSize: 20),
          textAlign: TextAlign.center,
        ),
      reverse: true,
      scrollDirection: Axis.horizontal,
      children: <Widget>[
        for (String item in items)
          Container(
            key: ValueKey(item),
            height: 100,
            margin: EdgeInsets.symmetric(horizontal: 50, vertical: 10),
            decoration: BoxDecoration(
                color:
                Colors.primaries[int.parse(item) % Colors.primaries.length],
                borderRadius: BorderRadius.circular(10)),
            child: Text(item,style: TextStyle(fontSize: 30),textAlign: TextAlign.center,),
          )
      ],
      onReorder: (int oldIndex, int newIndex) {
        if (oldIndex < newIndex) {
          newIndex -= 1;
        }
        var child = items.removeAt(oldIndex);
        items.insert(newIndex, child);
        setState(() {

        });
      },
    );
  }
}

